package com.cs.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cs.dao.StudentDaoImpl;
import com.cs.entity.Course;
import com.cs.entity.Grade;
import com.cs.entity.Student;

@Service
@Transactional
public class StudentServiceImpl {
	@Resource
	private StudentDaoImpl sDaoImpl;
	
	//学生登录
	public Student studentLogin(String sno,String spassword){
		Student student = this.sDaoImpl.studentLodin(sno, spassword);
		if (student!=null) {
			return student;
		}else {
			return null;
		}
	}
	//根据id查询个人信息
	public Student findStudentById(Integer id) {
		Student student = this.sDaoImpl.findStudentById(id);
		return student;
	}
	//根据id查询课程
	public Course findCourseById(Integer id) {
		return this.sDaoImpl.findCourseById(id);
	}
	//修改个人信息
	public boolean updateStudent(Student student) {
		return this.sDaoImpl.updateStudent(student);
	}
	//查询学生可选的课程
	public List<Course> findOptionalCourses(String specialities) {
		return this.sDaoImpl.findOptionalCourses(specialities);
	}
	//选课
	public void electiveCourse(Student student,Course course) {
		int number = course.getNumber();
		if (number>0) {
			student.getCourse().add(course);
			course.getStudent().add(student);
			/*List<Course> cList = student.getCourse();
			List<Student> sList = course.getStudent();
			cList.add(course);
			sList.add(student);
			student.setCourse(cList);
			course.setStudent(sList);*/
			course.setNumber(number-1);
			this.sDaoImpl.electiveCourse(student, course);
		}
	}
	//查看成绩
	public List<Grade> selectGrade(Integer id) {
		List<Grade> list = this.sDaoImpl.selectGrade(id);
		return list;
	}

}
